package com.example.mybatisplusdemo.model.dto;

import com.example.mybatisplusdemo.model.domain.Rating;
import com.example.mybatisplusdemo.model.domain.Review;
import com.example.mybatisplusdemo.model.domain.Store;
import com.example.mybatisplusdemo.model.domain.User;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Data
public class ReviewDTO extends Review {
    private User user;
    private Store store;
    private Byte score = 0;
    private Rating rating;

    //将DTO转换为Review实体
    public Review toReview() {
        Review review = new Review();
        BeanUtils.copyProperties(this, review);
        if (user != null) {
            review.setUserId(user.getId()); //设置user_id
        }
        return review;
    }
}
